local fufou = fk.CreateSkill{
  name = "lingling__fufou",
}

Fk:loadTranslationTable{
  ["lingling__fufou"] = "服否",
  [":lingling__fufou"] = "回合开始时，你可以指定一名其他角色，本回合每当你使用一张牌后，你可以弃置其一张牌；本回合结束时，"..
  "其可以失去1点体力与你各摸X张牌（X为你本回合弃置其牌数）。"..
  "<br><br> <font color = '#a40000'>先穷瀚海，再掀祁连。",

  ["#lingling__fufou-choose"] = "服否：选择一名角色，本回合每当你使用一张牌后，你可以弃置其一张牌",
  ["@@lingling__fufou-turn"] = "服否",
  ["#lingling__fufou-invoke"] = "服否：是否弃置 %dest 一张牌？",
  ["#lingling__fufou-draw"] = "服否：是否失去1点体力，和 %src 各摸%arg张牌？",
}

fufou:addEffect(fk.TurnStart, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(fufou.name) and
      #player.room:getOtherPlayers(player, false) > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      skill_name = fufou.name,
      prompt = "#lingling__fufou-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    player.room:setPlayerMark(to, "@@lingling__fufou-turn", player.id)
  end,
})

fufou:addEffect(fk.CardUseFinished, {
  anim_type = "control",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and
      table.find(player.room:getOtherPlayers(player, false), function (p)
        return p:getMark("@@lingling__fufou-turn") == player.id and not p:isNude()
      end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = table.find(room:getOtherPlayers(player, false), function (p)
      return p:getMark("@@lingling__fufou-turn") == player.id and not p:isNude()
    end)
    if to == nil then return end
    if room:askToSkillInvoke(player, {
      skill_name = fufou.name,
      prompt = "#lingling__fufou-invoke::"..to.id,
    }) then
      event:setCostData(self, {tos = {to}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local card = room:askToChooseCard(player, {
      target = to,
      flag = "he",
      skill_name = fufou.name,
    })
    room:throwCard(card, fufou.name, to, player)
  end,
})

fufou:addEffect(fk.TurnEnd, {
  anim_type = "control",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:usedEffectTimes("#lingling__fufou_2_trig", Player.HistoryTurn) > 0 and
      table.find(player.room:getOtherPlayers(player, false), function (p)
        return p:getMark("@@lingling__fufou-turn") == player.id and not p.dead
      end)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local to = table.find(room:getOtherPlayers(player, false), function (p)
      return p:getMark("@@lingling__fufou-turn") == player.id and not p.dead
    end)
    if to == nil then return end
    if room:askToSkillInvoke(to, {
      skill_name = fufou.name,
      prompt = "#lingling__fufou-draw:"..player.id.."::"..player:usedEffectTimes("#lingling__fufou_2_trig", Player.HistoryTurn),
    }) then
      event:setCostData(self, {tos = {to}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:loseHp(to, 1, fufou.name)
    local n = player:usedEffectTimes("#lingling__fufou_2_trig", Player.HistoryTurn)
    if not to.dead then
      to:drawCards(n, fufou.name)
    end
    if not player.dead then
      player:drawCards(n, fufou.name)
    end
  end,
})

return fufou
